<?php

namespace  Ekadmin\Controller;
use \Think\Controller;
use Think\Page;

class GoodsOrderController extends CommonController
{
    public  function index()
    {


        $param = I('get.');
        $where['uniacid'] = $this->uniacid;

        if($param['out_trade_no']){
            $where['out_trade_no'] = $param['out_trade_no'];
        }

        if($param['user']){
            $where['user'] = $param['user'];

        }

        if($param['start'] && !$param['end']){
            $where['addtime'] = array('gt',strtotime($param['start']));
        }
        if(!$param['start'] && $param['end']){
            $where['addtime'] = array('lt',strtotime($param['end']));
        }

        if($param['start'] && $param['end']){
            $where['addtime'] = array('between',[strtotime($param['start']),strtotime($param['end'])]);
        }
        


        $obj = M('reward_log');
        $count = $obj->where($where)->count();
        $this->assign('count',$count);
        $page = new Page($count);
        $data = $obj->where($where)->limit($page->firstRow.','.$page->listRows)->order('addtime desc')->select();
        foreach ($data as $k => $v)
        {

            $goods = M('goods')->where(['id'=>$v['goods_id']])->field('name,price,logo,id')->find();
            $data[$k]['goods'] = $goods;
        }

        $leiji = $obj->where(['uniacid'=>$this->uniacid])->sum('amount');
        $leijierror = $obj->where(['uniacid'=>$this->uniacid,'status'=>2])->sum('amount');
        //dump($data);die;

        $this->assign('data',$data);
        $this->assign('leiji',$leiji);
        $this->assign('leijierror',$leijierror);
        $this->assign('page',$page->show());
        $this->display();
    }




       






}